home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / test / process.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  4KB  |  125 lines

  1. /* Test class Process
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet:kgorlen@alw.nih.gov
  20.  
  21. Function:
  22.     
  23. Modification History:
  24.     
  25. $Log:    process.c,v $
  26.  * Revision 3.0  90/05/20  00:29:42  kgorlen
  27.  * Release for 1st edition.
  28.  * 
  29. */
  30. static char rcsid[] = "$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/test/RCS/process.c,v 3.0 90/05/20 00:29:42 kgorlen Rel $";
  31.  
  32. #include "StackProc.h"
  33. #include "HeapProc.h"
  34. #include "SharedQueue.h"
  35. #include "Scheduler.h"
  36. #include "String.h"
  37.  
  38. class TestStackProc : public StackProc {
  39. protected:
  40.     TestStackProc(const char* name, stackTy* bottom, int pri, SharedQueue& in, SharedQueue& out);
  41. public:
  42.     static TestStackProc* create(const char* name, int pri, SharedQueue& in, SharedQueue& out);
  43. };
  44.  
  45. TestStackProc::TestStackProc(const char* pname, stackTy* bottom, int pri, SharedQueue& in, SharedQueue& out)
  46.     : StackProc(pname,bottom,pri)
  47. {
  48.     if (FORK()) return;
  49.     while (YES) {
  50.         Object* msg = in.next();
  51.         cout << "StackProc " << name() << " received " << *msg << endl;
  52.         out.nextPut(*msg);
  53.         cout << "StackProc " << name() << " sent " << *msg << endl;
  54.     }
  55. }
  56.  
  57. TestStackProc* TestStackProc::create(const char* name, int pri, SharedQueue& in, SharedQueue& out)
  58. {
  59. #ifndef NESTED_TYPES
  60.     auto stackTy bottom;
  61. #else
  62.     auto Process::stackTy bottom;
  63. #endif
  64.     return new TestStackProc(name, &bottom, pri, in, out);
  65. }
  66.  
  67. class TestHeapProc : public HeapProc {
  68. protected:
  69. #ifndef NESTED_TYPES
  70.     TestHeapProc(const char* name, stackTy* bottom, int pri, SharedQueue& in, SharedQueue& out);
  71. #else
  72.     TestHeapProc(const char* name, Process::stackTy* bottom, int pri, SharedQueue& in, SharedQueue& out);
  73. #endif
  74. public:
  75.     static TestHeapProc* create(const char* name, int pri, SharedQueue& in, SharedQueue& out);
  76. };
  77.  
  78. #ifndef NESTED_TYPES
  79. TestHeapProc::TestHeapProc(const char* pname, stackTy* bottom, int pri, SharedQueue& in, SharedQueue& out)
  80. #else
  81. TestHeapProc::TestHeapProc(const char* pname, Process::stackTy* bottom, int pri, SharedQueue& in, SharedQueue& out)
  82. #endif
  83.     : HeapProc(pname,bottom,pri)
  84. {
  85.     if (FORK()) return;
  86.     while (YES) {
  87.         Object* msg = in.next();
  88.         cout << "HeapProc  " << name() << " received " << *msg << endl;
  89.         out.nextPut(*msg);
  90.         cout << "HeapProc  " << name() << " sent " << *msg << endl;
  91.     }
  92. }
  93.  
  94. TestHeapProc* TestHeapProc::create(const char* name, int pri, SharedQueue& in, SharedQueue& out)
  95. {
  96. #ifndef NESTED_TYPES
  97.     auto stackTy bottom;
  98. #else
  99.     auto Process::stackTy bottom;
  100. #endif
  101.     return new TestHeapProc(name, &bottom, pri, in, out);
  102. }
  103.  
  104. main()
  105. {
  106.     MAIN_PROCESS(0);
  107.     SharedQueue* q0 = new SharedQueue(2);
  108.     SharedQueue* qin = q0;
  109.     SharedQueue* qout;
  110.     for (int i=1; i<= MAXPRIORITY; i++) {
  111.         String pname = "P";
  112.         pname &= (char)('0'+i);
  113.         qout = new SharedQueue(2);
  114.         if (i & 2) TestHeapProc::create(pname,i,*qin,*qout);
  115.         else TestStackProc::create(pname,i,*qin,*qout);
  116.         qin = qout;
  117.     }
  118.     String& msg = *new String("THE MESSAGE");
  119.     Scheduler::dumpOn(cerr);
  120.     q0->dumpOn(cerr);
  121.     Scheduler::yield();
  122.     q0->nextPut(msg);
  123.     cout << *qout->next() << endl;
  124. }
  125.